This is my code and im getting this error: RangeError [EMBED_DESCRIPTION]: MessageEmbed description must be a string can can someone help me please? i want to make leaderboard
const { MessageEmbed } = require("discord.js");
const Discord = require('discord.js');
const Database = require("@replit/database");
const db = new Database();
module.exports = {
name: "Leaderboard",
aliases: ['leader', 'leaderboard', 'топ', 'Топ'],
run: async (client, message, args) => {
const collection = new Collection();
await Promise.all(
message.guild.members.cache.map(async (member) => {
const id = member.id;
const bal = await db.get(`balance_${id}`);
console.log(`${member.user.tag} -> ${bal}`);
return bal !== 0
? collection.set(id, {
id,
bal,
})
: null;
})
);
const data = collection.sort((a, b) => b.bal - a.bal).first(10);
message.channel.send(
new MessageEmbed()
.setTitle(`Leaderboard in ${message.guild.name}`)
.setDescription(
data.map((v, i) => {
return `${i + 1}) ${client.users.cache.get(v.id).tag} => **${v.bal} coins**`;
})
)
);
},
};```
In setDescription you're calling data.map(...) which returns an array. You can use Array.prototype.join to create a string from the array elements: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
data.map(...).join('\n')
If your array looked like this ['abc', 'def', 'ghi'] then the output of the join would be a string that looks like this:
abc
def
ghi